import axios from "axios";
import { ElMessage } from "element-plus";

export const BASE_URL = "https://qianniu.bingdou.site";
axios.defaults.baseURL = BASE_URL;
axios.defaults.headers.post["Content-Type"] = "application/json";

const service = axios.create({
  timeout: 10000,
});

service.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    console.log(error);
    return Promise.reject();
  }
);

service.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    const error_res = error.response?.data;
    ElMessage.error(error_res.message);
    return Promise.reject();
  }
);

export default service;
